package ru.st.selenium;

import org.testng.annotations.*;

import static org.junit.Assert.*;

import ru.st.selenium.model.User;
import ru.st.selenium.model.Film;

public class AddFilm_test extends ru.st.selenium.pages.TestBase{
	  
	@BeforeMethod
	public void mayBeLogout() {
		if (app.getUserHelper().isNotLoggedIn()) {
			return;
		}
	    app.getUserHelper().logout();
	}
	
	@Test
	public void testAddFilmTrue() throws Exception {
		User user = new User().setLogin("admin").setPassword("admin");
		Film film = new Film().setTitle("Test_"+System.currentTimeMillis()).setYear("2013");
		  
		app.getUserHelper().loginAs(user);
		assertTrue(app.getUserHelper().isLoggedInAs(user));
 
		app.getNavigationHelper().gotoMyCollectionPage();
		app.getNavigationHelper().gotoUserAddFilmPage();
		app.getFilmHelper().create(film);
		app.getFilmHelper().filmIsAdded();
		  
		app.getFilmHelper().delete(film);
	}
	
	@Test
	public void testAddFilmFalse() throws Exception {
		User user = new User().setLogin("admin").setPassword("admin");
		Film film = new Film().setTitle("Test_"+System.currentTimeMillis()).setYear("wrong");
		  
		app.getUserHelper().loginAs(user);
		assertTrue(app.getUserHelper().isLoggedInAs(user));

		app.getNavigationHelper().gotoMyCollectionPage();
		app.getNavigationHelper().gotoUserAddFilmPage();
		app.getFilmHelper().create(film);
		app.getFilmHelper().filmIsNotAdded();
	} 
}
